//
//  ChangePricePopViewController.m
//  FactorySale
//
//  Created by Huazhi_xi on 2021/1/15.
//  Copyright © 2021 主事丫环. All rights reserved.
//

#import "ChangePricePopViewController.h"

@interface ChangePricePopViewController ()
@property (weak, nonatomic) IBOutlet UIView *tipsView;
@property (weak, nonatomic) IBOutlet UITextField *contractPriceField;
@property (weak, nonatomic) IBOutlet UITextField *priceField;

@end

@implementation ChangePricePopViewController

- (instancetype)init {
    if (self = [super initWithNibName:nil bundle:nil]) {
        self.modalPresentationStyle = UIModalPresentationCustom;
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _contractPriceField.text = [NSString stringWithFormat:@"%.2f", _model.contractPrice];
    _priceField.text = [NSString stringWithFormat:@"%.2f", _model.salePrice];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self animationAlert:self.tipsView];
}
- (IBAction)cancelButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)confirmButtonClick:(UIButton *)sender {
    if ([_contractPriceField.text isEqual:@""]) {
        ShowToastWithText(@"请输入合同价");
        return;
    }
    if ([_priceField.text isEqual:@""]) {
        ShowToastWithText(@"请输入售价");
        return;
    }
    
    if ([_priceField.text floatValue] < [_contractPriceField.text floatValue]) {
        ShowToastWithText(@"售价要大于合同价...");
        return;
    }
    _confirmBtnClickBlock ? _confirmBtnClickBlock(_contractPriceField.text, _priceField.text) : nil;
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
